package com.inhim.pjhim.adapter.provider;

import android.content.Context;
import android.content.Intent;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chaychan.adapter.BaseItemProvider;
import com.inhim.pjhim.R;
import com.inhim.pjhim.activity.ProjectListActivity;
import com.inhim.pjhim.activity.ProjectRadioListActivity;
import com.inhim.pjhim.adapter.TagReaderListAdapter;
import com.inhim.pjhim.entity.ReaderTwo;
import com.inhim.pjhim.utils.ImageLoaderUtils;
import com.inhim.pjhim.view.CustomRoundAngleImageView;

/**
 * @author ChayChan
 * @description: 头部banner
 * @date 2018/3/22  14:48
 * 未使用
 */

public class ReaderTagItemTwoProvider extends BaseItemProvider<ReaderTwo, BaseViewHolder> {

    private Context context;
    public ReaderTagItemTwoProvider(Context context) {
        this.context=context;
    }

    @Override
    public void convert(BaseViewHolder helper, final ReaderTwo news, int i) {
        if (news == null) {
            //如果没有标题，则直接跳过
            return;
        }
        CustomRoundAngleImageView iv_title =helper.getView(R.id.iv_title);
        TextView tv_title = helper.getView(R.id.tv_title);
        TextView tv_content=helper.getView(R.id.tv_content);
        TextView tv_author=helper.getView(R.id.tv_author);
        TextView tv_section=helper.getView(R.id.tv_section);
        ConstraintLayout lin_1=helper.getView(R.id.constran);
        lin_1.setOnClickListener(v -> {
            Intent intent;
            if(news.getType()==1){
                intent=new Intent(context, ProjectListActivity.class);
                intent.putExtra("Title","阅读");
            }else if(news.getType()==2){
                intent=new Intent(context, ProjectListActivity.class);
                intent.putExtra("Title","视频");
            }else {
                intent=new Intent(context, ProjectRadioListActivity.class);
                intent.putExtra("Title","聆听");
            }
            intent.putExtra("TAG","ReaderItemProvider");
            intent.putExtra("readerTypeId",news.getReaderTypeId());
            intent.putExtra("ReaderTwo",news);
            intent.putExtra("Type",String.valueOf(news.getType()));
            context.startActivity(intent);
        });
        try{
            setText(tv_section,"共"+news.getTotal()+"课");
            if(news.getTagName()==null || "".equals(news.getTagName())){
                tv_content.setVisibility(View.GONE);
            }else{
                tv_content.setVisibility(View.VISIBLE);
                setText(tv_content,news.getTagName());
            }
            ConstraintLayout.LayoutParams Params   =  (ConstraintLayout.LayoutParams)iv_title.getLayoutParams();
            int mType=news.getType();
            if(mType==2||mType==1){
                Params.height = context.getResources().getDimensionPixelSize(R.dimen.base_dimen_85);
                Params.width = context.getResources().getDimensionPixelSize(R.dimen.base_dimen_140);
                if(news.getReadAmount()==null){
                    setText(tv_author,"0人已看");
                }else{
                    setText(tv_author,news.getReadAmount()+"人已看");
                }
            }else{
                Params.height = context.getResources().getDimensionPixelSize(R.dimen.base_dimen_100);
                Params.width = context.getResources().getDimensionPixelSize(R.dimen.base_dimen_80);
                if(news.getReadAmount()==null){
                    setText(tv_author,"0人已听");
                }else{
                    setText(tv_author,news.getDoubSort()+"人已听");
                }
            }
            iv_title.setLayoutParams(Params);
            setText(tv_title,news.getName());
            ImageLoaderUtils.setImage(news.getIcon(), iv_title);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    private void setText(TextView textView,String content){
        if(content!=null&&textView!=null){
            textView.setText(content);
        }
    }

    @Override
    public int viewType() {
        return TagReaderListAdapter.READER_TWO;
    }

    @Override
    public int layout() {
        return R.layout.provider_reader_tag_two;
    }

}
